<?php
/**
 * @author: justwkj
 * @date: 2021/8/26 22:43
 * @email: justwkj@gmail.com
 * @desc:
 */


/**
 * 记录日志
 * @param $log
 * @param string $type
 * @return false
 * @author: justwkj
 * @date: 2021/8/6 15:03
 */
function writeLog($log, $type = 'sql'){
    $path = ROOT_PATH.'runtime/log/';
    if (!is_dir($path) && !mkdir($path, 0755, true)) {
        //无权创建文件忽略函数
        return false;
    }
    if (is_array($log)) {
        //日志中文不转换
        $log = json_encode($log, JSON_UNESCAPED_UNICODE);
    }
    $filename = $path . date("Ymd") . '_' . $type . ".log";
    @$handle = fopen($filename, "a+");
    @fwrite($handle, date('Y-m-d H:i:s') . "  " . $log . "\r\n");
    @fclose($handle);
}
